#include "headfiles.h"

using namespace std;

void parenthesisRecur(char *str, int l, int r, int loc, int n) {
    if (l == r && r == n) {
        cout << str << endl;
        return;
    }

    if (l < n) {
        str[loc] = '(';
        parenthesisRecur(str, l + 1, r, loc + 1, n);
    }

    if (r < l) {
        str[loc] = ')';
        parenthesisRecur(str, l, r + 1, loc + 1, n);
    }
}

void parenthesisCombination(int n) {
    if (n <= 0) {
        cout << "Incorrect n value: " << n << endl;
        return;
    }

    char *str = (char *)malloc(sizeof(char) * 2 * n + 1);
    str[2 * n] = '\0';
    parenthesisRecur(str, 0, 0, 0, n);
    
    return;
}
